package cn.hchaojie.camp.day02.exercise;

/**
 * 求两个数的最大公约数
 * 
 */

public class GetMaxGcd {
	public static void main(String[] args) {
		System.out.println(maxGcd(5, 10));
		System.out.println(maxGcd(8, 12));
		System.out.println(maxGcd(8, 9));
	}
	
	public static int maxGcd(int a, int b) {
		int min = Math.min(a, b);
		
		for (int i = min; i > 1; i--) {
			if (a % i == 0 && b % i ==0) {
				return i;
			}
		}
		
		return -1;
	}
}
